//
//  BCOrderConfirmListCell.m
//  BangcaiBuy
//
//  Created by lsy on 16/7/2.
//  Copyright © 2016年 BCB. All rights reserved.
//

#import "BCOrderConfirmListCell.h"
#import "BCOrderConDetailCell.h"
@interface BCOrderConfirmListCell ()<UITableViewDelegate,UITableViewDataSource>
{
    UIView *headView;
    UILabel *headLab1;
    UILabel *headLab2;
    UILabel *headLab3;
    UILabel *headLab4;
    UILabel *headLab5;
    UILabel *headLine;
    
    UIView *footView;
    UILabel *footLine;
    UILabel *footLab1;
    UILabel *footLab2;
    UILabel *footLab3;
    UILabel *footLab4;
    UILabel *footLab5;
    UILabel *footLab6;
    
    


}
@property(nonatomic, strong)UITableView *table;

@end

@implementation BCOrderConfirmListCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}

- (void)createView
{
    headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40)];
    headLab1 = [[UILabel alloc] init];
    headLab2 = [[UILabel alloc] init];
    headLab3 = [[UILabel alloc] init];
    headLab4 = [[UILabel alloc] init];
    headLab5 = [[UILabel alloc] init];
    headLine = [[UILabel alloc] init];
    headLine.backgroundColor = [UIColor colorWithRed:0.941  green:0.941  blue:0.941 alpha:1];
    
    headLab1.text = @"品类";
    headLab1.font = [UIFont systemFontOfSize:13];
    headLab1.textColor = [UIColor colorWithRed:0.486  green:0.486  blue:0.486 alpha:1];
    headLab1.textAlignment = NSTextAlignmentCenter;
    headLab2.text = @"商品信息";
    headLab2.font = [UIFont systemFontOfSize:13];
    headLab2.textColor = [UIColor colorWithRed:0.486  green:0.486  blue:0.486 alpha:1];
    headLab2.textAlignment = NSTextAlignmentCenter;
    headLab3.text = @"规格";
    headLab3.font = [UIFont systemFontOfSize:13];
    headLab3.textColor = [UIColor colorWithRed:0.486  green:0.486  blue:0.486 alpha:1];
    headLab3.textAlignment = NSTextAlignmentCenter;
    headLab4.text = @"数量";
    headLab4.font = [UIFont systemFontOfSize:13];
    headLab4.textColor = [UIColor colorWithRed:0.486  green:0.486  blue:0.486 alpha:1];
    headLab4.textAlignment = NSTextAlignmentCenter;
    headLab5.text = @"小计";
    headLab5.font = [UIFont systemFontOfSize:13];
    headLab5.textColor = [UIColor colorWithRed:0.486  green:0.486  blue:0.486 alpha:1];
    headLab5.textAlignment = NSTextAlignmentCenter;
    
    
    [headView addSubview:headLab1];
    [headView addSubview:headLab2];
    [headView addSubview:headLab3];
    [headView addSubview:headLab4];
    [headView addSubview:headLab5];
    [headView addSubview:headLine];
    
    footView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 300)];
    footLab1 = [[UILabel alloc] init];
    footLab2 = [[UILabel alloc] init];
    footLab3 = [[UILabel alloc] init];
    footLab4 = [[UILabel alloc] init];
    footLab5 = [[UILabel alloc] init];
    footLab6 = [[UILabel alloc] init];
    footLine = [[UILabel alloc] init];
    footLine.backgroundColor = [UIColor colorWithRed:0.941  green:0.941  blue:0.941 alpha:1];

    footLab4.text = @"商品总额 :";
    footLab4.font = [UIFont systemFontOfSize:12];
    footLab4.textAlignment = NSTextAlignmentRight;
    footLab4.textColor = [UIColor colorWithRed:0.486  green:0.486  blue:0.486 alpha:1];
    
    footLab5.text = @"配送费 :";
    footLab5.font = [UIFont systemFontOfSize:12];
    footLab5.textAlignment = NSTextAlignmentRight;
    footLab5.textColor = [UIColor colorWithRed:0.486  green:0.486  blue:0.486 alpha:1];
    
    footLab6.text = @"优惠券 :";
    footLab6.font = [UIFont systemFontOfSize:12];
    footLab6.textAlignment = NSTextAlignmentRight;
    footLab6.textColor = [UIColor colorWithRed:0.486  green:0.486  blue:0.486 alpha:1];
    
    footLab1.font = [UIFont systemFontOfSize:12];
    footLab1.textAlignment = NSTextAlignmentRight;
    footLab1.textColor = [UIColor colorWithRed:0.998  green:0.371  blue:0 alpha:1];
 
    footLab2.font = [UIFont systemFontOfSize:12];
    footLab2.textAlignment = NSTextAlignmentRight;
    footLab2.textColor = [UIColor colorWithRed:0.998  green:0.371  blue:0 alpha:1];
    
    footLab3.font = [UIFont systemFontOfSize:12];
    footLab3.textAlignment = NSTextAlignmentRight;
    footLab3.textColor = [UIColor colorWithRed:0.998  green:0.371  blue:0 alpha:1];
    
    
    
    [footView addSubview:footLab1];
    [footView addSubview:footLab2];
    [footView addSubview:footLab3];
    [footView addSubview:footLab4];
    [footView addSubview:footLab5];
    [footView addSubview:footLab6];
    [footView addSubview:footLine];
    
    self.arr = [BCOrderViewManager readStuffFromOrder];
    
    self.table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 28*_arr.count+65+40) style:UITableViewStylePlain];
    self.table.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.table.delegate = self;
    self.table.dataSource = self;
    self.table.scrollEnabled = NO;
    self.table.tableHeaderView = headView;
    self.table.tableFooterView = footView;
    [self.contentView addSubview:self.table];
    
}

- (void)layoutSubviews{
    __block CGFloat price = 0;
    [self.arr enumerateObjectsUsingBlock:^(ORDER* stuff, NSUInteger idx, BOOL * _Nonnull stop) {
        price +=stuff.count.integerValue * stuff.price.floatValue;
        
    }];
    footLab1.text = [NSString stringWithFormat:@"¥ %.2f", price];
    footLab2.text = @"¥ 50";
    footLab3.text = @"- ¥ 5";

    [headLab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(36 *wx);
        make.height.mas_equalTo(20);
        make.centerY.mas_equalTo(0);
    }];
    [headLab2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(headLab1.mas_right).mas_equalTo(40*wx);
        make.height.mas_equalTo(20);
        make.centerY.mas_equalTo(0);
    }];
    [headLab3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(headLab2.mas_right).mas_equalTo(40*wx);
        make.height.mas_equalTo(20);
        make.centerY.mas_equalTo(0);
    }];
    [headLab4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(headLab3.mas_right).mas_equalTo(53*wx);
        make.height.mas_equalTo(20);
        make.centerY.mas_equalTo(0);
    }];
    [headLab5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(headLab4.mas_right).mas_equalTo(53 *wx);
        make.height.mas_equalTo(20);
        make.centerY.mas_equalTo(0);
    }];
    
    [headLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(headView);
        make.left.mas_equalTo(12);
        make.right.mas_equalTo(-12);
        make.height.mas_equalTo(1);
        
    }];
    
    
    
    [footLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(footView);
        make.left.mas_equalTo(12);
        make.right.mas_equalTo(-12);
        make.height.mas_equalTo(1);
    }];
    
    [footLab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-25);
        make.height.mas_equalTo(20);
        make.top.mas_equalTo(12);
    }];
    
    [footLab2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-25);
        make.height.mas_equalTo(20);
        make.top.mas_equalTo(44);
    }];
    
    [footLab3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-25);
        make.height.mas_equalTo(20);
        make.top.mas_equalTo(76);
    }];
    
    [footLab4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(footLab1.mas_left);
        make.height.mas_equalTo(20);
        make.top.equalTo(footLab1);
    }];
    [footLab5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(footLab2.mas_left);
        make.height.mas_equalTo(20);
        make.top.equalTo(footLab2);
    }];
    [footLab6 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(footLab3.mas_left);
        make.height.mas_equalTo(20);
        make.top.equalTo(footLab3);
    }];
    
    

    
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 20;
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *reuse = @"reuse";
    BCOrderConDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
    if(!cell) {
        cell = [[BCOrderConDetailCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuse];
    }
    ORDER *stuff = self.arr[indexPath.row];
    switch (stuff.category.integerValue) {
        case 0:
            cell.category = @"禽蛋肉类";
            break;
        case 1:
            cell.category = @"水果蔬菜";
            break;

        default:
            break;
    }
    cell.name = stuff.name;
    cell.unit = stuff.unit;
    cell.amount = stuff.count;
    cell.price = [NSNumber numberWithDouble:stuff.count.integerValue * stuff.price.floatValue];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.arr.count;
}



@end
